import 'dart:ffi';

import 'package:flutter/material.dart';
import 'package:flutter_application_1/home.dart';
import 'package:flutter_application_1/user.dart';

// ignore: must_be_immutable
class CustomerTabs extends StatefulWidget {
  // const CustomerTabs({super.key});

  Map? argrments;

  CustomerTabs({super.key, this.argrments});

  @override
  State<CustomerTabs> createState() => _CustomerTabsState();
}

class _CustomerTabsState extends State<CustomerTabs> {
  /*页面索引*/
  int _currentIndex = 0;

/*页面*/
  List<Widget> _pages = [GHHomePage(), GHUserPage()];

/*页面控制器*/
  final _pageController = PageController();

/*tabbarItems*/
  List<BottomNavigationBarItem> _barItems = [
    BottomNavigationBarItem(
        label: '首页', icon: Icon(Icons.home), activeIcon: Icon(Icons.home)),
    BottomNavigationBarItem(
        label: '我的',
        icon: Icon(Icons.settings),
        activeIcon: Icon(Icons.settings)),
  ];

  @override
  void dispose() {
    super.dispose();
    _pageController.dispose();
  }

  @override
  /*声明_pages和_barItems*/
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: PageView.builder(
          physics: NeverScrollableScrollPhysics(),
          controller: _pageController,
          onPageChanged: (int index) {
            setState(() {
              _currentIndex = index;
            });
          },
          itemBuilder: (context, index) {
            return _pages[index];
          },
        ),
        bottomNavigationBar: BottomNavigationBar(
          items: _barItems,
          currentIndex: _currentIndex,
          backgroundColor: Colors.white,
          selectedItemColor: Colors.blue,
          unselectedItemColor: Colors.grey,
          selectedFontSize: 12,
          unselectedFontSize: 12,
          onTap: (int index) {
            _pageController.jumpToPage(index);
          },
        ),
      );
  }
}
